package uk.co.agileworks.bidpirate.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "ITEM_ITEMNUMBER",
		"USER_ID" }) })
public class Bid extends ModelObject {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	private Long id;
	private Double maxBid;
	@ManyToOne
	@JoinColumn(name = "ITEM_ITEMNUMBER")
	private Item item;
	@ManyToOne
	@JoinColumn(name = "USER_ID")
	private User user;
	private String statusCode = Status.NOT_ACTIVE.name();

	private transient String itemNumberOrUrl;

	public Long getId() {
		return id;
	}

	public Item getItem() {
		return item;
	}

	public String getItemNumberOrUrl() {
		return itemNumberOrUrl;
	}

	public Double getMaxBid() {
		return maxBid;
	}

	public Status getStatus() {
		return Status.valueOf(statusCode);
	}

	public User getUser() {
		return user;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public void setItemNumberOrUrl(String itemNumberOrUrl) {
		this.itemNumberOrUrl = itemNumberOrUrl;
	}

	public void setMaxBid(Double maxBid) {
		this.maxBid = maxBid;
	}
	
	public void setStatus(Status status) {
		this.statusCode = status.name();
	}
	
	public void setUser(User user) {
		this.user = user;
	}
	
	public boolean isAlert() {
		return getStatus() == Status.NOT_ACTIVE;
	}

}
